package com.tedu.charging.service.user.controller;

import com.tedu.charging.common.pojo.web.ServerResult;
import com.tedu.charging.service.user.pojo.param.VehicleBindParam;
import com.tedu.charging.common.pojo.vo.VehicleVO;
import com.tedu.charging.service.user.service.IUserVehicleBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class VehicleBindController {
    @Autowired
    IUserVehicleBindService userVehicleBindService;

    /**
     * 添加车辆绑定
     * @param vehicleBindParam
     * @return
     * @throws Throwable
     */
    @PostMapping("/insertVehicleBind")
    public ServerResult<Integer> insertVehicleBind(@RequestBody VehicleBindParam vehicleBindParam) throws Throwable{
        Integer vehicleId = userVehicleBindService.insertVehicleBind(vehicleBindParam);
        return ServerResult.success(vehicleId);
    }

    /**
     * 获取用户车辆信息
     * @param userId
     * @return
     * @throws Throwable
     */
    @GetMapping("/getVehicleByUserId/{userId}")
    public ServerResult<VehicleVO> getVehicleByUserId(@PathVariable("userId") Integer userId) throws Throwable{
        VehicleVO vehicleVO = userVehicleBindService.getVehicleByUserId(userId);

        return new ServerResult<VehicleVO>(0,"success",vehicleVO);
    }

    /**
     * 解绑
     * @param userId
     * @param vehicleId
     * @return
     * @throws Throwable
     */
    @GetMapping("/unBind")
    public ServerResult<Boolean> unBind(Integer userId,Integer vehicleId) throws Throwable{
        boolean result = userVehicleBindService.unBind(userId, vehicleId);
        return ServerResult.success(result);
    }
}
